package com.topsoft.email.config.redis;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.topsoft.email.service.IUserInfoService;


@Configuration
public class RedisConfigBean {
	
	@Resource
	IUserInfoService userInfoService;
	
	
	@Bean
	public RedisConnectionFactory  redisCF(){
		JedisConnectionFactory cf=new JedisConnectionFactory();
		String ip=userInfoService.getDatathread().getUserName();
		cf.setHostName(ip);
		cf.setPort(6379);
		return cf;
	}
	
	@Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory cf){
    	RedisTemplate<String, String>  redis=new RedisTemplate<String, String>();
    	redis.setConnectionFactory(cf);
    	redis.setKeySerializer(new StringRedisSerializer());
		return redis;
    }
	
	
	
	
	
	

}
